<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>申报系统</title>
    <link rel="stylesheet" href="cssase.css">
    <link rel="stylesheet" href="cssodify.css">
    <link rel="stylesheet" href="js/layui/css/layui.css"/>
    <link rel="stylesheet" href="css/index.css"/>
    <link rel="stylesheet" href="css/modify.css"/>


<style>
.btn-wrap {
    width: 150px;
    margin: 60px auto 0;
    overflow: hidden;
}
</style>
</head>
<body>
    <div class='top'>
        <img onclick="goHome1()" style="cursor:pointer" src="img/logotext.png">&nbsp;|&nbsp;<span>修改信息</span>
    </div>
    <div class="contWrap">
        <ul>
            <li class="clearfix">
                <div class="oLeft">
                    <label>账户名称:</label>
                    <input class="zhmc" disabled type="text">
                </div>
                <div class="oRight">
                    <p id="user">修改账户名称</p>
                </div>
            </li>
            <li class="clearfix">
                <div class="oLeft">
                    <label>手机号码:</label>
                    <input class="sjhm" disabled type="text">
                </div>
                <div class="oRight">
                    <p id="phone">修改手机号</p>
                </div>
            </li>
            <li class="clearfix">
                <div class="oLeft">
                    <label>邮箱:</label>
                    <input class="yx" disabled type="text">
                </div>
                <div class="oRight">
                    <p id="yx">修改邮箱</p>
                </div>
            </li>
            <li class="clearfix">
                <div class="oLeft">
                    <label>密码:</label>
                    <input class="mm" disabled type="password">
                </div>
                <div class="oRight">
                    <p id="xgmm">修改密码</p>
                </div>
            </li>
            <li class="clearfix">
                <div class="oLeft">
                    <label>备注:</label>
                    <input class="bz" disabled type="text">
                </div>
                <div class="oRight">
                    <p id="bz">修改备注</p>
                </div>
            </li>
        </ul>
        <div class="btn-wrap">
                        <a  href="fillpage.html">返回</a>
                      
                    </div>
    </div>
    <div id="userBox" style="display:none;padding:30px">
        <form class="layui-form" action="">
            <div class="layui-form-item" style="white-space:nowrap!important;">
              <label class="layui-form-label" style="padding-left:10px">原始账户名称</label>
              <div class="layui-input-block">
                <input type="text" name="title" required class="zhmc1 layui-input" lay-verify="required" disabled placeholder="" autocomplete="off">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">新账户名称</label>
              <div class="layui-input-block">
                <input type="text" name="title" required class="newZhmc layui-input" lay-verify="required" placeholder="请输入新账户名称" autocomplete="off">
              </div>
            </div>
        </form>
    </div>
    <div id="phoneBox" style="display:none;padding:30px">
        <form class="layui-form" action="">
            <div class="layui-form-item" style="white-space:nowrap!important;">
              <label class="layui-form-label" style="padding-left:10px">原始手机号</label>
              <div class="layui-input-block">
                <input type="text" name="title" class="sjhm1 layui-input" disabled lay-verify="required" autocomplete="off">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">新手机号</label>
              <div class="layui-input-block">
                <input type="text" name="title" required class="newSjhm layui-input"  lay-verify="required" placeholder="请输入新手机号" autocomplete="off">
              </div>
            </div>
        </form>
    </div>
    <div id="yxBox" style="display:none;padding:30px">
        <form class="layui-form" action="">
            <div class="layui-form-item" style="white-space:nowrap!important;">
              <label class="layui-form-label" style="padding-left:10px">原始邮箱</label>
              <div class="layui-input-block">
                <input type="text" name="title" class="yx1 layui-input" disabled lay-verify="required" autocomplete="off">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">新邮箱</label>
              <div class="layui-input-block">
                <input type="text" name="title" required class="newYx layui-input" lay-verify="required" placeholder="请输入新邮箱" autocomplete="off">
              </div>
            </div>
        </form>
    </div>
    <div id="xgmmBox" style="display:none;padding:30px">
        <form class="layui-form" action="">
            <div class="layui-form-item" style="white-space:nowrap!important;">
                <label class="layui-form-label" style="padding-left:10px">原始密码</label>
                <div class="layui-input-block">
                  <input type="password" name="title" required class="ysMm layui-input" lay-verify="required" placeholder="请输入原密码" autocomplete="off">
                </div>
              </div>
            <div class="layui-form-item" style="white-space:nowrap!important;">
              <label class="layui-form-label" style="padding-left:10px">新密码</label>
              <div class="layui-input-block">
                <input type="password" name="title" required class="newMm layui-input" lay-verify="required" placeholder="请输入密码" autocomplete="off">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">确认密码</label>
              <div class="layui-input-block">
                <input type="password" name="title" required class="newMm2 layui-input"  lay-verify="required" placeholder="请输入密码" autocomplete="off">
              </div>
            </div>
        </form>
    </div>
    <div id="bzBox" style="display:none;padding:30px">
        <form class="layui-form" action="">
            <div class="layui-form-item" style="white-space:nowrap!important;">
              <label class="layui-form-label" style="padding-left:10px">原始备注</label>
              <div class="layui-input-block">
                <input type="text" name="title" disabled class="bz1 layui-input" lay-verify="required" autocomplete="off">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">新备注</label>
              <div class="layui-input-block">
                <input type="text" name="title" required class="newBz layui-input" lay-verify="required" placeholder="请输入新备注" autocomplete="off">
              </div>
            </div>
        </form>
    </div>
    <script src="jsquery-1.9.1.min.js"></script>
    <script src="jsayui/layui.js"></script>
    <script src="jsklConfig.js"></script>
    <script src="jsssha256.js"></script>
    <script>
        var userName = "";
        var userId = "";
        //获取用户名
        $.ajax({
            type: "get",
            url: qklUrl+"/front/blockchain/getUsername",
            headers:{token:getCookie('token')?getCookie('token'):'',"Content-Type":"application/json"},
            //contentType: "application/json", //必须有
            async:false,  
            dataType: "json", //表示返回值类型，不必须
            success: function (result) {
                if(result.status == 0){
                    // $("#user").html("欢迎,"+result.message);
                    userName = result.message;
                }else if(result.status == -1){
                    window.location.href='login.html';
                }
            },
            error:function(){
                console.log("服务器连接失败");
            }
        });
        $.ajax({
            type: "get",
            url:qklUrl+"/othercited/getUserId?username="+userName,
            headers:{token:getCookie('token')?getCookie('token'):'',"Content-Type":"application/json"},
            async:false,  
            dataType: "json", //表示返回值类型，不必须
            success: function (result) {
                console.log(result);
                if(result.status == 0){
                    userId = result.data;
                }
            },
            error:function(){
                console.log("服务器连接失败");
            }
        });
        //获取用户信息
        getUserInfo();
        function getUserInfo(){
            $.ajax({
                type: "get",
                url: qklUrl+"/front/blockchain/getuserinfo",
                headers:{token:getCookie('token')?getCookie('token'):'',"Content-Type":"application/json"},
                //contentType: "application/json", //必须有
                async:false,
                dataType: "json", //表示返回值类型，不必须
                success: function (result) {
                    if(result.status == 0){
                        $(".zhmc").val(result.data.username);
                        $(".sjhm").val(result.data.mobile);
                        $(".yx").val(result.data.email);
                        $(".mm").val(result.data.password);
                        $(".bz").val(result.data.comment.length!=0 && result.data.comment!=null?result.data.comment:'');

                        $(".zhmc1").val(result.data.username);
                        $(".sjhm1").val(result.data.mobile);
                        $(".yx1").val(result.data.email);
                        $(".mm1").val(result.data.password);
                        $(".bz1").val(result.data.comment.length!=0 && result.data.comment!=null?result.data.comment:'');
                    }
                },
                error:function(){
                    console.log("服务器连接失败");
                }
            });
        }
        // 校验
        var mobileReg = /^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8}$/; //手机号正则表达式
        var emailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;//邮箱正则表达式
        var pswReg = /^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘'，。、])[0-9a-zA-Z!~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘'，。、]{6,18}$/;//密码格式校验

        layui.use(['layer','form'], function(){
            var form = layui.form;
            var layer = layui.layer;
            $("#user").click(function(){
                layer.open({
                    type: 1, 
                    title:"修改账户名称",
                    area:['500px','400px'],
                    btn: ['确定', '取消'], 
                    content: $("#userBox"),
                    yes:function(index,layero){
                      if($(".newZhmc").val().length!=0){
                        $.ajax({
                            type: "post",
                            url: qklUrl+"/othercited/updateUser",
                            headers:{token:getCookie('token')?getCookie('token'):''},
                            contentType: "application/json", //必须有
                            data:JSON.stringify({
                                id:userId,
                                acctName:userName,
                                userName:$(".newZhmc").val(),
                                email:$(".yx").val(),
                                mobile:$(".sjhm").val(),
                                password:$(".mm").val(),
                                remarks:$(".bz").val()
                            }),
                            async:false,  
                            dataType: "json", //表示返回值类型，不必须
                            success: function (result) {
                                if(result.status == 0){
                                    layer.close(index);
                                    layer.msg(result.message,{icon:6});
                                    quitLogin();
                                }else{
                                    layer.msg(result.message,{icon:5});
                                }
                            },
                            error:function(){
                                console.log("服务器连接失败");
                            }
                        });
                      }else{
                        layer.msg('请输入新的账户名称', {
                            icon: 5,
                        });
                      }
                    }
                }); 
            });
            function goHome1(){
    window.location.href="fillpage.html";
}
            $("#phone").click(function(){
                layer.open({
                    type: 1, 
                    title:"修改手机号",
                    area:['500px','400px'],
                    btn: ['确定', '取消'], 
                    content: $("#phoneBox"),
                    yes:function(index,layero){
                        if($(".newSjhm").val().length == 0){
                            layer.msg('请输入新的手机号', {
                                icon: 5,
                            });
                            return false;
                        }else if(!mobileReg.test($(".newSjhm").val())){
                            layer.msg('请输入正确的手机号', {
                                icon: 5,
                            });
                            return false;
                        }else{
                            $.ajax({
                                type: "post",
                                url: qklUrl+"/othercited/updateUser",
                                headers:{token:getCookie('token')?getCookie('token'):''},
                                contentType: "application/json", //必须有
                                data:JSON.stringify({
                                    id:userId,
                                    acctName:userName,
                                    mobile:$(".newSjhm").val(),
                                    userName:$(".zhmc").val(),
                                    email:$(".yx").val(),
                                    password:$(".mm").val(),
                                    remarks:$(".bz").val()
                                }),
                                async:false,  
                                dataType: "json", //表示返回值类型，不必须
                                success: function (result) {
                                    if(result.status == 0){
                                        layer.close(index);
                                        layer.msg(result.message,{icon:6});
                                        getUserInfo();
                                    }else{
                                        layer.msg(result.message,{icon:5})
                                    }
                                },
                                error:function(){
                                    console.log("服务器连接失败");
                                }
                            });
                        }
                    }
                }); 
            });
            $("#yx").click(function(){
                layer.open({
                    type: 1, 
                    title:"修改邮箱",
                    area:['500px','400px'],
                    btn: ['确定', '取消'], 
                    content: $("#yxBox"),
                    yes:function(index,layero){
                        if($(".newYx").val().length==0){
                            layer.msg('请输入新的邮箱', {
                                icon: 5,
                            });
                            return false;
                        }else if(!emailReg.test($(".newYx").val())){
                            layer.msg('邮箱格式不正确', {
                                icon: 5,
                            });
                            return false;
                        }else{
                            $.ajax({
                                type: "post",
                                url: qklUrl+"/othercited/updateUser",
                                headers:{token:getCookie('token')?getCookie('token'):''},
                                contentType: "application/json", //必须有
                                data:JSON.stringify({
                                    id:userId,
                                    acctName:userName,
                                    mobile:$(".sjhm").val(),
                                    userName:$(".zhmc").val(),
                                    password:$(".mm").val(),
                                    remarks:$(".bz").val(),
                                    email:$(".newYx").val()
                                }),
                                async:false,  
                                dataType: "json", //表示返回值类型，不必须
                                success: function (result) {
                                    if(result.status == 0){
                                        layer.close(index);
                                        layer.msg(result.message,{icon:6});
                                        getUserInfo();
                                    }else{
                                        layer.msg(result.message,{icon:5})
                                    }
                                },
                                error:function(){
                                    console.log("服务器连接失败");
                                }
                            });
                        }
                    }
                }); 
            });
            $("#xgmm").click(function(){
                layer.open({
                    type: 1, 
                    title:"修改密码",
                    area:['500px','400px'],
                    btn: ['确定', '取消'], 
                    content: $("#xgmmBox"),
                    yes:function(index,layero){
                        if($(".ysMm").val().length==0){
                            layer.msg('请输入原始密码', {
                                icon: 5,
                            });
                            return false;
                        }else if(SHA256_hash($(".ysMm").val())!=$(".mm").val()){
                            layer.msg('原始密码不正确', {
                                icon: 5,
                            });
                            return false;
                        }else if($(".newMm").val().length==0){
                            layer.msg('请输入新密码', {
                                icon: 5,
                            });
                            return false;
                        }else if(!pswReg.test($(".newMm").val())){
                            layer.msg('新密码需6-18位密码大小写字母加数字加特殊符号',{icon:5});
                            return false;
                        }else if($(".newMm2").val().length==0){
                            layer.msg('请输入确认密码', {
                                icon: 5,
                            });
                            return false;
                        }else if($(".newMm").val()!=$(".newMm2").val()){
                            layer.msg('确认密码与新密码不一致',{icon:5});
                            return false;
                        }else{
                            $.ajax({
                                type: "post",
                                url: qklUrl+"/othercited/updateUser",
                                headers:{token:getCookie('token')?getCookie('token'):''},
                                contentType: "application/json", //必须有
                                data:JSON.stringify({
                                    id:userId,
                                    acctName:userName,
                                    password:SHA256_hash($(".newMm").val()),
                                    mobile:$(".sjhm").val(),
                                    userName:$(".zhmc").val(),
                                    email:$(".yx").val(),
                                    remarks:$(".bz").val()
                                }),
                                async:false,  
                                dataType: "json", //表示返回值类型，不必须
                                success: function (result) {
                                    if(result.status == 0){
                                        layer.close(index);
                                        layer.msg(result.message,{icon:6});
                                        quitLogin();
                                    }else{
                                        layer.msg(result.message,{icon:5})
                                    }
                                },
                                error:function(){
                                    console.log("服务器连接失败");
                                }
                            });
                        }
                    }
                }); 
            });
            $("#bz").click(function(){
                layer.open({
                    type: 1, 
                    title:"修改备注",
                    area:['500px','400px'],
                    btn: ['确定', '取消'], 
                    content: $("#bzBox"),
                    yes:function(index,layero){
                        if($(".newBz").val().length!=0){
                            $.ajax({
                                type: "post",
                                url: qklUrl+"/othercited/updateUser",
                                headers:{token:getCookie('token')?getCookie('token'):''},
                                contentType: "application/json", //必须有
                                data:JSON.stringify({
                                    id:userId,
                                    acctName:userName,
                                    remarks:$(".newBz").val(),
                                    mobile:$(".sjhm").val(),
                                    userName:$(".zhmc").val(),
                                    password:$(".mm").val(),
                                    email:$(".yx").val()
                                }),
                                async:false,  
                                dataType: "json", //表示返回值类型，不必须
                                success: function (result) {
                                    if(result.status == 0){
                                        layer.close(index);
                                        layer.msg(result.message,{icon:6});
                                        getUserInfo();
                                    }else{
                                        layer.msg(result.message,{icon:5})
                                    }
                                },
                                error:function(){
                                    console.log("服务器连接失败");
                                }
                            });
                        }else{
                            layer.msg('请输入新的备注', {
                                icon: 5,
                            });
                        }
                    }
                }); 
            })
        })
    </script>
</body>
</html>